<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh">
<head lang="en">
    <th:block th:include="include :: header('首页')"/>
</head>
<body>
<form class="layui-form" style="padding: 10px" lay-filter="form">
    <div class="layui-form-item">
        <label class="layui-form-label">管理员</label>
        <div class="layui-input-block">
            <input type="text" id="username" name="username" lay-verify="required" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="text" id="password" name="password"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">确认密码</label>
        <div class="layui-input-block">
            <input type="text" id="password2" name="password2"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">真实姓名</label>
        <div class="layui-input-block">
            <input type="text" id="realName" name="realName" lay-verify="required" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <label class="layui-form-label">所属角色</label>
    <div class="layui-input-block">
        <select id="rid" name="rid" lay-verify="required" lay-search="">

        </select>
    </div>
    <input type="hidden" id="id" name="id">
    <div style="display: none">
        <button class="layui-btn" lay-submit lay-filter="*" id="submit">立即提交</button>
    </div>
</form>
<th:block th:include="include :: footer" />
<script type="text/javascript">

    //从父层获取值，json是父层的全局js变量。eval是将该string类型的json串变为标准的json串
    layui.use(['form'], function () {
        var form = layui.form;
        config.commGet('/sysUser/authRoleTree.json', function (list) {
            var role = document.getElementById("rid");        //add_role_name给select定义的id
            for (var i = 0; i < list.length; i++) {
                var option = document.createElement("option");    // 创建添加option属性
                option.setAttribute("value", list[i].roleId);                  // 给option的value添加值
                option.innerText = list[i].roleName;             // 打印option对应的纯文本 （超级管理员、管理员）
                role.appendChild(option);                          // 给select 添加option子标签
            }
            if (parent.json) {
                var parent_json = parent.json;
                form.val("form", {
                    "username": parent_json.username
                    , "realName": parent_json.realName
                    , "id": parent_json.id
                    , "rid": parent_json.rid
                })
            }
            form.render("select");                                // 刷性select，显示出数据
        })
        form.on('submit(*)', function (data) {
            if (data.field.password !== data.field.password2) {
                config.alert("两次密码输入不一致");
                return false;
            }
            config.commPost("/sysUser/UpauthRole.json", data.field, function (data, info) {
                parent.config.tableRefresh();
                parent.config.closeLayer(info);
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

    })

    function ApplicationSave() {
        document.getElementById("submit").click();
    }
</script>
</body>
</html>

